const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    menu: cc.Node = null;
    @property(cc.Node)
    back: cc.Node = null;

    onLoad() {
        this.menu.children.forEach(v => {
            v.on(cc.Node.EventType.TOUCH_END, this.choose, this);
        })
        this.back.on(cc.Node.EventType.TOUCH_END, this.backEvent, this);
        this.back.parent = cc.director.getScene();
        cc.game.addPersistRootNode(this.back)
        this.back.position = cc.v2(cc.winSize.width * 0.9, cc.winSize.height * 0.9)
    }



    choose(touch: cc.Event.EventTouch) {
        let button = touch.target;
        let sceneName = button.children[0].children[0].getComponent(cc.Label).string;
        cc.director.loadScene(sceneName, () => {
            let backBtn = cc.find('backBtn');
            backBtn.position = cc.v2(cc.winSize.width - backBtn.width / 2, cc.winSize.height - backBtn.height / 2)
        })
    }

    backEvent(touch: cc.Event.EventTouch) {
        cc.director.loadScene('main');
        touch.target.destroy();
    }

    update(dt) {

    }
}
